package com.eat.fish_service.controller.wx;

import com.eat.common_utils.R;
import com.eat.fish_service.entity.DiseaseQuery;
import com.eat.fish_service.service.DiseasesEncyclopediaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController("wxFishDiseasesWxController")
@CrossOrigin
@RequestMapping("/wx/fishdiseases")
@Slf4j
@Api(tags = "微信鱼病百科")
public class FishDiseasesController {

        @Autowired
        private DiseasesEncyclopediaService diseasesEncyclopediaService;

        @ApiOperation(value = "上传鱼病的图片，返回图片路径，添加鱼百科的时候调用")
        @PostMapping("addFishDiseaseBaiKePic")
        public R uploadDiseaseFishPic(MultipartFile pic){
            return diseasesEncyclopediaService.addFishDiseaseBaiKePic(pic);
        }

        @ApiOperation(value = "将鱼病的类名，鱼病的介绍，鱼病图的路径，文章作者存入数据库")
        @PostMapping("addFishBaiKe")
        public R addFishDiseaseBaiKe(@RequestParam @ApiParam(name = "diseaseName", value = "鱼病的类名", required = false) String diseaseName,
                                     @RequestParam @ApiParam(name = "introduction", value = "鱼病的介绍", required = false) String introduction,
                                     @RequestParam @ApiParam(name = "fishDiseaseImg", value = "鱼病的图片路径", required = false) String fishDiseaseImg,
                                     @RequestParam @ApiParam(name = "author", value = "文章作者", required = false) String author){

            return diseasesEncyclopediaService.addFishDiseaseBaiKe(diseaseName, introduction, fishDiseaseImg, author);
        }

        //条件查询鱼病百科带分页文件数据
        @ApiOperation(value = "条件查询鱼病带分页数据")
        @PostMapping("getFishBaiKe/{current}/{size}")
        public R pageFishDiseasesCondition(@PathVariable
                                                   @ApiParam(name = "current", value = "当前页", required = true) Long current,
                                           @PathVariable
                                                   @ApiParam(name = "size", value = "每页显示条数", required = true)  Long size,
                                           @RequestBody(required = false)
                                                   @ApiParam(name = "fishQuery", value = "查询对象条件，鱼病的介绍模糊查询，鱼病类名和作者等值查询，时间范围查询", required = false) DiseaseQuery diseaseQuery) {
            return diseasesEncyclopediaService.pageFishDiseaseCondition(current, size, diseaseQuery);
        }

    //查询鱼病百科带分页文件数据
    @ApiOperation(value = "根据id查询鱼病数据")
    @GetMapping("getFishBaiKe/{fishDiseaseId}")
    public R getFishDiseaseCondition(@PathVariable @ApiParam(name = "fishDiseaseId", value = "鱼病Id", required = true) String fishDiseaseId){
        return diseasesEncyclopediaService.getFishDisease(fishDiseaseId);

   }
 }

